import request from '@/utils/request'
import store from '@/store'
// 查询Guestbook列表
export function listGuestbook(query) {
    return request({
        url: '/api/v1/guestbookList',
        method: 'get',
        params: query
    }).then(function (res) {
         
        let boolOptions = store.getters.parameter.sys_bool;
       
        res.data.list.forEach((item, index) => {
            
            for (let key in item) {
                 
                if (key == "isReplyed") {
                    item[key] = getDictLabelByValue(item[key],boolOptions)
                }
               

            }
             
            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;

    })
}


function getDictLabelByValue(value, dict_list) {
    let dictLabel = "";
    if (dict_list) {
        dict_list.forEach((_item, index) => {
            if (_item.dictValue == value) {
                dictLabel = _item.dictLabel
            }
        })
        return dictLabel;
    } else {
        console.log(value);
        return;
    }

}

// 查询Guestbook详细
export function getGuestbook(guestbookId) {
    return request({
        url: '/api/v1/guestbook/' + guestbookId,
        method: 'get'
    })
}


// 新增Guestbook
export function replayGuestbook(data) {
    return request({
        url: '/api/v1/guestbook',
        method: 'post',
        data: data
    })
}

// 修改Guestbook
export function updateGuestbook(data) {
    return request({
        url: '/api/v1/guestbook',
        method: 'put',
        data: data
    })
}

// 删除Guestbook
export function delGuestbook(guestbookId) {
    return request({
        url: '/api/v1/guestbook/' + guestbookId,
        method: 'delete'
    })
}
